1 package uk.ac.roe.antigen.dialogs; 2 3 import java.awt.BorderLayout; 4 import java.awt.Dimension; 5 import java.awt.Toolkit; 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener; 8 import java.awt.event.WindowAdapter; 9 import java.awt.event.WindowEvent; 10 import java.util.logging.Level; 11 import java.util.logging.Logger; 12 13 import javax.swing.BorderFactory; 14 import javax.swing.ImageIcon; 15 import javax.swing.JButton; 16 import javax.swing.JPanel; 17 import javax.swing.JTextArea; 18 import javax.swing.border.BevelBorder; 19 import javax.swing.border.TitledBorder; 20 21 import uk.ac.roe.antigen.utils.Config; 22 23 public class AbortDialog extends javax.swing.JDialog { 24 /*** 25 * Logger for this class 26 */ 27 private static final Logger logger = Logger.getLogger(AbortDialog.class.getName()); 28 29 private JPanel jPanel1; 30 private JTextArea errorMessageLabel; 31 private JButton okBtn; 32 private String message="Large red error message"; 33 34 /*** 35 * Auto-generated main method to display this JDialog 36 */ 37 public static void main(String[] args) { 38 if (logger.isLoggable(Level.FINER)) { 39 logger.finer("start"); 40 } 41 42 BuildLoggerFrame frame = new BuildLoggerFrame(); 43 AbortDialog inst = new AbortDialog(frame,"Something went wrong!"); 44 BorderLayout instLayout = new BorderLayout(); 45 inst.getContentPane().setLayout(instLayout); 46 inst.setVisible(true); 47 48 if (logger.isLoggable(Level.FINER)) { 49 logger.finer("end"); 50 } 51 } 52 53 public AbortDialog(BuildLoggerFrame frame, String message) { 54 super(frame); 55 if (logger.isLoggable(Level.FINER)) { 56 logger.finer("start"); 57 } 58 59 this.frame=frame; 60 this.message=message; 61 62 initGUI(); 63 64 if (logger.isLoggable(Level.FINER)) { 65 logger.finer("end"); 66 } 67 } 68 69 private BuildLoggerFrame frame; 70 71 private void initGUI() { 72 if (logger.isLoggable(Level.FINER)) { 73 logger.finer("start"); 74 } 75 76 try { 77 setSize(400, 250); 78 79 this.addWindowListener(new WindowAdapter() { 80 public void windowClosing(WindowEvent arg0) { 81 frame.shutDown(); 82 } 83 }); 84 { 85 jPanel1 = new JPanel(); 86 this.getContentPane().add(jPanel1, BorderLayout.SOUTH); 87 { 88 okBtn = new JButton(); 89 jPanel1.add(okBtn); 90 okBtn.setText("OK"); 91 okBtn.setBounds(175, 235, 60, 30); 92 okBtn.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/stop.png"))); 93 94 okBtn.addActionListener(new ActionListener() { 95 public void actionPerformed(ActionEvent evt) { 96 setVisible(false); 97 frame.shutDown(); 98 } 99 }); 100 } 101 } 102 { 103 errorMessageLabel = new JTextArea(); 104 this.getContentPane().add(errorMessageLabel, BorderLayout.CENTER); 105 errorMessageLabel.setFont(new java.awt.Font("Dialog",0,14)); 106 errorMessageLabel.setForeground(new java.awt.Color(255,0,0)); 107 String borderTitle = Config.getProperty("antigen.dialog.bordertitle","antigen"); 108 errorMessageLabel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(BevelBorder.RAISED, null, null), borderTitle, TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("Eurostile",0,12), new java.awt.Color(0,0,255))); 109 errorMessageLabel.setLineWrap(true); 110 errorMessageLabel.setWrapStyleWord(true); 111 errorMessageLabel.setText(message); 112 } 113 } catch (Exception e) { 114 logger.warning("exception: " + e); 115 116 e.printStackTrace(); 117 } 118 this.setLocation(getDialogLocation().width, getDialogLocation().height); 119 120 if (logger.isLoggable(Level.FINER)) { 121 logger.finer("end"); 122 } 123 } 124 125 126 /*** 127 * Calculates the desired location of the dialog on the screen. By default 128 * it is in the center of the screen. 129 * 130 * @return the desired location of the dialog on the screen 131 */ 132 private Dimension getDialogLocation() { 133 if (logger.isLoggable(Level.FINER)) { 134 logger.finer("start"); 135 } 136 137 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); 138 Dimension dlgInputDim = this.getSize(); 139 int dlgInputX = (int) ((screenDim.getWidth() - dlgInputDim.getWidth()) / 2); 140 int dlgInputY = (int) ((screenDim.getHeight() - dlgInputDim.getHeight()) / 2); 141 142 if (logger.isLoggable(Level.FINER)) { 143 logger.finer("end"); 144 } 145 return new Dimension(dlgInputX, dlgInputY); 146 } 147 }